//
//  test.cpp
//  test_cpp
//
//  Created by Camille Xu on 2023/3/14.
//  Copyright © 2023年 Camille Xu. All rights reserved.
//
#include <iostream>
#include <vector>
#include <string>
#include <limits.h>
using namespace std;

void dfs(vector<vector<int>>& nums, vector<vector<int>>& result, int dep, vector<int>& cur) {
    if (cur.size() == nums.size()) {
        result.push_back(cur);
    } else {
        for (int i = 0; i < nums[dep].size(); ++i) {
            cur.push_back(nums[dep][i]);
            dfs(nums, result, dep + 1, cur);
            cur.pop_back();
        }
    }
}

int main() {
    vector<vector<int>> nums = {{1, 2}, {3, 4, 5}};
    vector<vector<int>> result;
    vector<int> cur;
    dfs(nums, result, 0, cur);
    for (int i = 0; i < result.size(); ++i) {
        for (int j = 0; j < result[i].size(); ++j) {
            cout << result[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}
